package com.yeyks.app.controller.base.hotel;

import cn.hutool.core.util.StrUtil;
import com.yeyks.app.annotation.LoadUserId;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.constants.hotel.HotelSourceType;
import com.yeyks.common.convert.DateEditor;
import com.yeyks.commonReference.service.hotel.HotelInfoService;
import com.yeyks.commonReference.service.hotel.HotelSearchBaseService;
import com.yeyks.hotel.param.HotelInfoHotelSearchHotelInfoParam;
import com.yeyks.hotel.vo.HotelInfoHotelSearchHotelInfoVo;
import com.yeyks.search.pojo.vo.search.HotelInfoHotelUnionSearchVoHotle;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author fuchangshuai
 * @date 2019/3/26 4:27 PM
 */
@Api(tags = "酒店接口", description = "酒店")
@Slf4j
@RestController("appHotelInfoController")
@RequestMapping(value = "/app/hotel")
public class HotelInfoController {

    @Autowired
    private HotelInfoService hotelInfoService;
    @Autowired
    private HotelSearchBaseService hotelSearchBaseService;

    @InitBinder
    public void initbinder(WebDataBinder webDataBinder) {
        webDataBinder.registerCustomEditor(Date.class, new DateEditor());
    }

    /**
     * 获取如何退款
     *
     * @param hotelId
     * @return
     */
    @ApiOperation(value = "获取退款规则:v3.6")
    @PostMapping(value = "/getRefund")
    public AjaxResponseBody<List<String>> docRefund(String sourceType) {
        if(StrUtil.isBlank(sourceType)){
            sourceType = HotelSourceType.YYKS;
        }
        return AjaxResponseBody.success(getRefund(sourceType));
    }

    private List<String> getRefund(String sourceType) {
        List<String> list = new ArrayList<>();
        switch (sourceType) {
            case HotelSourceType.YYKS:
                list.add("1.以入住当天18:00为基准");
                list.add("2.18:00点之前全额退款");
                list.add("3.18:00点之后不能退款");
                list.add("4.下单后30分钟未付款将取消订单");
                break;
            default:
                list.add("1. 该客房预订后不支持退款");
                break;
        }
        return list;
    }

    //v3.4
    @ApiOperation(value = "酒店详情,搜索用:v3.5")
    @RequestMapping(value = "/hotelSearchHotelInfo", method = RequestMethod.POST)
    public AjaxResponseBody<HotelInfoHotelSearchHotelInfoVo> hotelSearchHotelInfo(@Validated @LoadUserId HotelInfoHotelSearchHotelInfoParam param) {
        HotelInfoHotelSearchHotelInfoVo hotelInfoHotelSearchHotelInfoVo = hotelInfoService.hotelSearchHotelInfo(param);
        return AjaxResponseBody.success(hotelInfoHotelSearchHotelInfoVo);
    }

    //v3.6
    @ApiOperation(value = "酒店详情,搜索用:v3.6")
    @RequestMapping(value = "/hotelUnionSearchHotelInfo", method = RequestMethod.POST)
    public AjaxResponseBody<HotelInfoHotelUnionSearchVoHotle> hotelUnionSearchHotelInfo(@Validated @LoadUserId HotelInfoHotelSearchHotelInfoParam param) {
        HotelInfoHotelUnionSearchVoHotle hotelInfoHotelUnionSearchVoHotle = hotelSearchBaseService.hotelSearchHotelInfo(param);
        return AjaxResponseBody.success(hotelInfoHotelUnionSearchVoHotle);
    }

}
